package cn.geracomium.util.web.page;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class PageResult implements Serializable {
    private HttpServletRequest request; // 接收Request对象引用
    private Integer pageSize ;
    private Integer pageNum ;
    private Integer empType ;
    private Integer empStatus ;

    public PageResult() {
        this.request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }
    public Integer getPageNum() {
        Integer pageNum = 1;
        try {
            if (this.request.getParameter("pageNum") != null) {
                pageNum = Integer.parseInt(this.request.getParameter("pageNum"));
            }
        } catch (Exception e) {
            return pageNum;
        }
        return pageNum;
    }


    public Integer getPageSize() {
        Integer pageSize = 3;
        try {
            if (this.request.getParameter("pageSize") != null) {
                pageSize = Integer.parseInt(this.request.getParameter("pageSize"));
            }
        } catch (Exception e) {
            return pageSize ;
        }
        return pageSize;
    }

    public String getKeyWord() {
        String keyWord = request.getParameter("keyWord"); // 接收查询关键字
        if (keyWord == "" || "null".equals(keyWord)) {

            return null ;
        }
        return keyWord;
    }

    public Date getBeginDate() throws ParseException {
        try {
            String date = this.request.getParameter("inductionStart");
            return new SimpleDateFormat("yyyy-MM-dd").parse(date);
        } catch (Exception e) {
            return null;
        }
    }

    public Date getEndDate() throws ParseException {
        try {
            String date = this.request.getParameter("inductionEnd");
            return new SimpleDateFormat("yyyy-MM-dd").parse(date);
        } catch (Exception e) {
            return null;
        }
    }

    public Integer getEmpType() {
        try {
            return Integer.parseInt(this.request.getParameter("employeeType"));
        } catch (Exception e) {
            return null;
        }
    }

    public Integer getEmpStatus() {
        try {
            return Integer.parseInt(this.request.getParameter("qEmpStatus"));
        } catch (Exception e) {
            return null;
        }
    }

}
